namespace Link_eLab.Helper.TypeConvert
{
    public static class TypeConvert
    {
        /// <summary>
        /// 转换decimal到string，不保留末尾0
        /// "0.12000" -> "0.12"
        /// https://stackoverflow.com/questions/3104615/best-way-to-display-decimal-without-trailing-zeroes
        /// </summary>
        /// <param name="value"></param>
        /// <returns>JSON结果集</returns>
        public static string TrimDecimalString(decimal? value)
        {
            string strValue = value.ToString(); //Get the stock string

            //If there is a decimal point present
            if (strValue.Contains("."))
            {
                //Remove all trailing zeros
                strValue = strValue.TrimEnd('0');

                //If all we are left with is a decimal point
                if (strValue.EndsWith(".")) //then remove it
                    strValue = strValue.TrimEnd('.');
            }

            return strValue;
        }
    }
}